package com.fc.service.impl;

import java.util.List;

import org.hibernate.Criteria
import org.hibernate.criterion.Projections
import org.hibernate.criterion.Restrictions
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional;

import com.fc.service.UnitOfMeasurementService
import com.fc.entities.FoodGroup
import com.fc.entities.UnitOfMeasurement

@Repository("quantityService")
@Transactional
class UnitOfMeasurementServiceImpl extends BaseServiceImpl<UnitOfMeasurement> implements UnitOfMeasurementService {
	@Override
	List<String> getAllNames() {
		Criteria criteria = currentSession().createCriteria(UnitOfMeasurement.class, "UnitOfMeasurement").setProjection(Projections.projectionList().add(Projections.property("UnitOfMeasurement.name")));
		return criteria.list();
	}

	UnitOfMeasurement findByName(String name) {
		Criteria criteria = currentSession().createCriteria(UnitOfMeasurement.class);
		UnitOfMeasurement uom = (UnitOfMeasurement) criteria.add(Restrictions.eq("name", name)).uniqueResult();
		return uom;
	}

	@Override
	List<UnitOfMeasurement> findAll() {
		findAll(UnitOfMeasurement.class)
	}
}
